﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNAFight.Characters;
using XNAFight.Characters.Core;
using XNAFight.Engine.Inputs;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;


namespace XNAFight.Players
{
    public class Player
    {
        #region CHAMPS

        Character personnage;
        Controler control;
        FightInputInterpreter interpreter;
        InGameInputConfiguration input_configuration;

        private ContentManager contentManager;
        
        #endregion

        #region PROPRIETES

        public Controler Control
        {
            get { return control; }
        }

        public Character Personnage
        {
            get { return personnage; }
        }

        public InGameInputConfiguration Input_Configuration
        {
            get { return input_configuration; }
        }

        #endregion
        
        public Player(ContentManager _contentManager, string _nom_perso, Controler _control, InGameInputConfiguration _input_configuration, Vector2 _pos_depart)
        {
            contentManager = _contentManager;
            personnage = getCharacterFromName(_nom_perso, _pos_depart);
            control = _control;
            input_configuration = _input_configuration;
            interpreter = new FightInputInterpreter();
        }

        public void Update(GameTime gameTime, Character ennemi)
        {
            if (Control != null)
            {
                if (control.Type == InputType.Keyboard)
                    personnage.Buffer.Update(interpreter.getKeyboardMoves((InGameKeyboardConfiguration)input_configuration, personnage.LookRight));
                else
                    personnage.Buffer.Update(interpreter.getPadMoves((InGamePadConfiguration)input_configuration, personnage.LookRight));
            }

            Personnage.Position_Ennemi = ennemi.Position;
        }

        private Character getCharacterFromName(string _name, Vector2 _pos_depart)
        {
            Character character = null;

            switch (_name)
            {
                case "Ryu": character = new Ryu(contentManager, _pos_depart);
                    break;
                case "Guile": character = new Guile(contentManager, _pos_depart);
                    break;
                case "Zangief": character = new Zangief(contentManager, _pos_depart);
                    break;
            }


            return character;
        }
        
    }
}
